package com.ruoyi.merchant.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.merchant.domain.ExceptionValue;
import com.ruoyi.merchant.service.IExceptionValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 异常指标记录Controller
 * 
 * @author xin.jucheng
 * @date 2024-03-28
 */
@RestController
@RequestMapping("/value")
public class ExceptionValueController extends BaseController
{
    @Autowired
    private IExceptionValueService exceptionValueService;

    /**
     * 查询异常指标记录列表
     */
    @RequiresPermissions("system:value:list")
    @GetMapping("/list")
    public TableDataInfo list(ExceptionValue exceptionValue)
    {
        startPage();
        List<ExceptionValue> list = exceptionValueService.selectExceptionValueList(exceptionValue);
        return getDataTable(list);
    }

    /**
     * 导出异常指标记录列表
     */
    @RequiresPermissions("system:value:export")
    @Log(title = "异常指标记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExceptionValue exceptionValue)
    {
        List<ExceptionValue> list = exceptionValueService.selectExceptionValueList(exceptionValue);
        ExcelUtil<ExceptionValue> util = new ExcelUtil<ExceptionValue>(ExceptionValue.class);
        util.exportExcel(response, list, "异常指标记录数据");
    }

    /**
     * 获取异常指标记录详细信息
     */
    @RequiresPermissions("system:value:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(exceptionValueService.selectExceptionValueById(id));
    }

    /**
     * 新增异常指标记录
     */
    @RequiresPermissions("system:value:add")
    @Log(title = "异常指标记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExceptionValue exceptionValue)
    {
        return toAjax(exceptionValueService.insertExceptionValue(exceptionValue));
    }

    /**
     * 修改异常指标记录
     */
    @RequiresPermissions("system:value:edit")
    @Log(title = "异常指标记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExceptionValue exceptionValue)
    {
        return toAjax(exceptionValueService.updateExceptionValue(exceptionValue));
    }

    /**
     * 删除异常指标记录
     */
    @RequiresPermissions("system:value:remove")
    @Log(title = "异常指标记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(exceptionValueService.deleteExceptionValueByIds(ids));
    }
}
